package com.scau402.system1.cipher;

import com.scau402.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

@Getter
@AllArgsConstructor
public enum CipherEnum {

    CIPHER_CONFIG1(1, new CipherHandlerImpl1()),
    CIPHER_CONFIG2(2, new CipherHandlerImpl2()),
    ;


    private final long typeId;

    private final CipherHandler handler;

    public static CipherEnum getByTypeId(long typeId) {
        return Arrays.stream(values())
                .filter(item -> Objects.equals(item.getTypeId(), typeId))
                .findFirst()
                .orElseThrow(() -> new ServiceException("typeId参数异常"));
    }
}
